package com.activiti.listener;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;

/**
 * @author ldanniel
 */
public class ProcessTaskListener {
    public static void main(String[] args) {
        ProcessTaskListener processTaskListener = new ProcessTaskListener();
        processTaskListener.startListener();
    }
    public void deployment(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deployment = repositoryService.createDeployment()
                //禁用架构验证
                .disableSchemaValidation()
                .name("测试监听器")
                .addClasspathResource("bpmn/evection-listener.bpmn")
                .deploy();
        System.out.println("流程部署 - id = " + deployment.getId());
        System.out.println("流程部署名称 = " + deployment.getName());

    }
    public void startListener(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        RuntimeService runtimeService = processEngine.getRuntimeService();
        //启动流程实例
        ProcessInstance testListener = runtimeService.startProcessInstanceByKey("testListener");
        System.out.println("testListener -DeploymentId--- " + testListener.getDeploymentId());
        System.out.println("testListener -Name--- " + testListener.getName());
        System.out.println("testListener -Id--- " + testListener.getId());
    }
}
